﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework.Graphics;
using System.Collections;
using Microsoft.Xna.Framework;

namespace Basics
{
    class DebugPanel
    {
        class DebugPanelEntry
        {
            public string Name { get; set; }
            public string Value { get; set; }
            public Vector2 RelativePosition { get; set; }

            public DebugPanelEntry(string name, string value, Vector2 relativePosition)
            {
                this.Name = name;
                this.Value = value;
                this.RelativePosition = relativePosition;
            }

            public string GetPairString()
            {
                return this.Name + "  =  " + this.Value;
            }
        }

        private Texture2D background;
        private SpriteFont font;
        private List<DebugPanelEntry> entries;
        private Vector2 nextLinePosition;
        private int lineSpacing;
        private float fontScale;
        public Vector2 Position { get; set; }
        public bool Visible { get; set; }

        public DebugPanel(Vector2 position, SpriteFont font)
        {
            this.Position = position;
            this.font = font;
            entries = new List<DebugPanelEntry>();
            this.lineSpacing = 30;
            this.fontScale = 1;
            this.nextLinePosition = new Vector2(10, 0);
        }

        public DebugPanel(Vector2 position, SpriteFont font, int lineSpacing, int fontScale)
        {
            this.Position = position;
            this.font = font;
            entries = new List<DebugPanelEntry>();
            this.lineSpacing = lineSpacing;
            this.fontScale = fontScale;
            this.nextLinePosition = new Vector2(10, 0);
        }

        public void AddEntry(string name, string value)
        {
            this.nextLinePosition = new Vector2(this.nextLinePosition.X, this.nextLinePosition.Y + this.lineSpacing);
            DebugPanelEntry newEntry = new DebugPanelEntry(name, value, this.nextLinePosition);
            entries.Add(newEntry);
        }

        public void Draw(SpriteBatch spriteBatch)
        {
            spriteBatch.Begin();
            foreach (DebugPanelEntry entry in entries)
            {
                spriteBatch.DrawString(this.font, entry.GetPairString(), this.Position + entry.RelativePosition, Color.White);
            }
            spriteBatch.End();
            
        }
    }
}
